<?php include_once 'include/header.php'; ?>
<?php include_once 'activitycontroller.php'; ?>
<div id="content">
    <?php include_once 'include/leftsidebar.php' ?>
    <div id="cmiddle">
        <div id="content-middle">           
            <div style="margin-top:20px">
                <div  style="line-height: 36px;height:36px;border-bottom:1px solid #ccc;margin-top:30px;background: url('Images/icon/beer.png') no-repeat 5px center">
                    <b style="font-size: 1.5em;padding-left:30px">Tin tức nhậu nhẹt & du lịch</b>
                </div> 
            </div>
            <div id="top-form" style="margin:10px;border-bottom: 1px solid #ccc;padding-bottom: 10px;">
                <form action="" method="POST" id="tour-form">
                    <input type="hidden" id="checksubmit" name="checksubmit" value="submittour"/>
                    <input type="hidden" id="getvalue" name="act_val" value=""/>
                    <input class="borderinput" type="text" id="chude" name="chude" value="" style="width:480px" placeholder="Chủ đề nhậu nhẹt...."/>
                    <br/><br/>
                    <input class="borderinput" type="text" id="ngaybatdau" name="ngaybatdau" value="" placeholder="Ngày bắt đầu..."/>
                    <input class="borderinput" type="text" id="sotienphaidong" name="sotienphaidong" value="" placeholder="Số tiền phải đóng..."/>
                    <br/><br/>
                    <input class="borderinput" type="text" id="diadiem1" name="diadiem" value="" style="width:480px" placeholder="Địa điểm diễn ra...."/>
                    <br/><br/>
                    <textarea class="borderinput" id="mieuta" name="mieuta"   placeholder="miêu tả chi tiết...." style="width:480px;height:30px"></textarea>
                    <br/><br/>
                    <div style="float: right;margin:5px 15px">
                        <div style="text-align: center">
                            <img class="img-border" title="Đi nhậu nhẹt ăn uống" src="Images/icon/beer_logo.png" alt="beer"/>
                        </div>
                        <div style="text-align: center">
                            <input checked type="radio" name="image" value="beer_logo.png"/>
                        </div>
                    </div>
                    <div style="float: right;margin:5px">
                        <div style="text-align: center">
                            <img class="img-border" title="Đi du lịch" src="Images/icon/car.png" alt="beer"/>
                        </div>
                        <div style="text-align: center">
                            <input type="radio" name="image" value="car.png"/>
                        </div>
                    </div>
                    <div style="float: right;margin:5px">
                        <div style="text-align: center">
                            <img class="img-border" title="Đi hát karaoke" src="Images/icon/karaoke.png" alt="beer"/>
                        </div>
                        <div style="text-align: center">
                            <input type="radio" name="image" value="karaoke.png"/>
                        </div>
                    </div>
                    <div style="float: right;margin:5px;line-height: 70px;font-weight: bold;">
                        Chọn hình thức 
                    </div>
                    <div style="clear: both"></div>
					<?php if(isset($_COOKIE["username"])){ ?>
                    <a href="#" class="button tour" onclick="return saveAct();"><span class="icon plus"></span>Lưu tin</a>
					<?php }else{ ?>
					<a href="register.php" class="button" onclick=""><span class="icon plus"></span>Đăng ký để đăng tin</a>
					<?php } ?>
                </form>                
            </div>
            <?php foreach ($list_act as $row) { ?>
                <div class="content-post-comment" style="border-bottom: 1px solid #ccc;padding-bottom:8px;">
                    <div class="post-item" style="position: relative">
                        <?php if($row[8] == $_COOKIE["id"]){ ?>
                        <div style="position: absolute;bottom:2px;right:5px;">
                            <img style="cursor: pointer" title="Nhấn vào đây để sửa thông tin" class="tipsy edit_tour" tid="<?php echo $row[0] ?>" src="Images/icon/edit.png"/>
                        </div>
                        <?php } ?>
                        <div style="float:left;margin:10px;">
                            <img width="48px" height="48px" class="img-border" src="Images/icon/<?php echo $row["image"] ?>"/><br/>
                            <?php if($row[8] == $_COOKIE["id"]){ ?>
                            <a class="delete_tour link" tid="<?php echo $row[0] ?>" href="#">Xóa bài này</a>
                            <?php } ?>
                        </div>
                        <div style="margin:10px;float:left;width:400px;word-wrap:break-word;">
                            <b style="color:#3d4fbb"><?php echo $row["chude"] ?></b>
                            <br/>
                            <br/>     
                            <?php $date = date("d/m/Y g:i:a", strtotime("{$row["ngaybatdau"]}")) ?>
                            <b>Người đăng tin:</b> <span style="font-weight: bold;color:#3d4fbb" class="tipsy" title="SĐT Liên hệ: <?php echo $row["sodienthoai"] ?>"><?php echo $row["fullname"] ?> (MSV: <?php echo $row["masv"] ?>)</span><br/><br/>
                            <b>Ngày bắt đầu: </b> <?php echo $date ?><br/><br/>
                            <b>Tiền phải đóng: </b> <?php echo number_format($row["sotienphaidong"], 0, '.', '.') ?> VNĐ<br/><br/>
                            <b>Địa điểm: </b> <?php echo $row["diadiem"] ?><br/><br/>
                            <b>Miêu tả: </b> <?php echo $row["mieuta"] ?>                                                       
                        </div>
                        <div style="clear: both"></div>
                    </div>
                </div>                  
            <?php } ?>            
        </div>
    </div>
    <?php include_once 'include/rightsidebar.php'; ?>
</div>
<script type="text/javascript">   
    function saveAct(){           
            var reg = /^[0-9]+$/;
            if($("#chude").val() != "" && $("#ngaybatdau").val() != "" && $("#sotienphaidong").val() != "" && $("#diadiem1").val() && reg.test($("#sotienphaidong").val())){
                $("#tour-form").submit();  
            }else{
                $("#chude").css("background","#FFEDEF");
                $("#ngaybatdau").css("background","#FFEDEF");
                $("#sotienphaidong").css("background","#FFEDEF");
                $("#diadiem1").css("background","#FFEDEF");
            }                      
            return false;
                
    }
    $(function(){
        $("#ngaybatdau").datetimepicker({
            showSecond: true,
            timeFormat: 'hh:mm:ss'
        });
        $(".edit_tour").click(function(){
           var id = $(this).attr("tid");
           $.post("activitycontroller.php?action=get_data_tour&id="+id,null,function(data){
               if(data != ""){
                   $("#chude").val(data.chude);
                   $("#ngaybatdau").val(data.ngaybatdau);
                   $("#sotienphaidong").val(data.sotienphaidong);
                   $("#diadiem1").val(data.diadiem);
                   $("#mieuta").val(data.mieuta);
                   $("#getvalue").val(data.id);
                   window.location = "tour.php#content-middle";
                   $(".tour").html("Sửa tin này");
                   $("#checksubmit").val("updatetour");
               }
           },"json")
        });
        $(".delete_tour").click(function(){
            var id = $(this).attr("tid");
            if(confirm("Bạn có muốn xóa bài viết này?")){
              $.ajax({
               url:"activitycontroller.php?action=delete_tour&id="+id,
               type:"GET",
               success:function(data){
                   if(data == true){
                     location.reload();  
                   }                   
               }
           })   
            }           
           return false;
        });
    })
    
</script>

<?php include_once 'include/footer.php' ?>